//
//  publicHeader.h
//  CarOnlineConsult
//
//  Created by 黄卫 on 17/2/24.
//  Copyright © 2017年 huangwei. All rights reserved.
//

#ifndef CarOnlineConsult_publicHeader_h
#define CarOnlineConsult_publicHeader_h

//----------------------公共通用宏---------------------------

/** 登录后保存的用户ID, 保存的value为 NSString 类型*/
#define UserIDUserDefaultsKey           @"operatorId"

/** 请求服务端Cookie */
#define RequestHeadCookieKey            @"sessionCookies"

/** 相册相关描述*/
#define GJCameraLibrary                 (@"从相册选择")
#define GJPhotograph                    (@"拍照")

/** 图片压缩率*/
#define GJMaxPixelSize                  (Screen_Width)

/** 数据库名称 */
#define AppFMDBName                     @"icarbonx.sqlite"

/** 钱币符号 */
#define GJ_Money_header                 @"￥"



/** 是否是免费用户 */
#define isFreeUser ([GJGlobalManager shareInstance].currentShopInfo.shop.buyvType.intValue==0)
#define isGreenShop ([GJGlobalManager shareInstance].currentShopInfo.shop.shopIdentity.intValue==1)
#define isRedShop ([GJGlobalManager shareInstance].currentShopInfo.shop.shopIdentity.intValue==2)

//--------------- 第三方SDK App Key ----------------------
/** 一点管家-高德地图API */
#define PLMAMapAppKey                   (@"6024b55b0fb9f13ffe44f04cab677c6b")
/** 一点管家-微信AppId */
#define WXAppId                         @"wx07a5ab15d521b077"
/** 一点管家-QQ AppId*/
#define QQAppId                         @"1105110319"
/** 环信AppKey */
#define HX_AppKey (@"1139161107115977#ydgjwcl")
#define HX_AppKey_py (@"1178161108115568#ydgj")

//用户消息拓展
#define IM_Nick                (@"nick")
#define IM_Avatar              (@"avatar")

/* 获取iOS系统版本 */
#define KsystemVersion                  [[[UIDevice currentDevice] systemVersion] floatValue]
/*  获取App版本号 */
#define XcodeAppVersion                 [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]
/*  弱引用 */
#define WEAKSELF                        typeof(self) __weak weakSelf = self;
/*  强引用 */
#define STRONGSELF                        typeof(weakSelf) __strong strongSelf = weakSelf;

//定义UIImage对象，图片多次被使用到
#define ImageNamed(name)                [UIImage imageNamed:name]


/*---------------------打印日志--------------------------*/
//重写NSLog,Debug模式下打印日志和当前行数
#if DEBUG
#define NSLog(FORMAT, ...) fprintf(stderr,"\nfunction:%s line:%d content:\n%s\n", __FUNCTION__, __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#else
#define NSLog(FORMAT, ...) nil
#endif


/*-----------------------系统警告框-------------------------*/

/** 系统提示Alert弹框, (此弹框只有一个按钮,没有事件只做提示使用) */
#define SystemAlertView(titleStr,messageStr,cancelTitle) [GJAlertView alertWithCallBackBlock:nil title:titleStr message:messageStr cancelButtonName:cancelTitle otherButtonTitles: nil];


/**  没有网络弹框提示, 参数为是否需要返回当前函数 */
#define JudgeNetWorkFailAlertShouldReturn(shouldReturn)    { \
    if (![Reachability isInternetConnection]) {\
        SystemAlertView(nil, NetworkConnectFail, @"好的");\
        if(shouldReturn == YES){\
            return;\
        }\
}\
}

//判断是否 Retina屏、设备是否%fhone 5、是否是iPad
#define isRetina                                    ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)

//检查系统版本   equal相等   greater大 less 小
#define System_Version_Equal_To(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define System_Version_Greater_Than(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define System_Version_Greater_Than_Or_Equal_To(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define System_Version_Less_Than(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define System_Version_Less_Than_Or_Equal_To(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)


/*-----------------------系统字体-------------------------*/
#define FontCustomSize(s)               [UIFont systemFontOfSize:s] //设置字体大小  (细体字)[UIFont fontWithName:@"Heiti SC" size:s]


/*----------------------适配屏幕----------------------------*/
#define IS_IPHONE4      (([[UIScreen mainScreen] bounds].size.height == 480) ? YES : NO)
#define IS_IPHONE_5     ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )
#define IS_IPHONE5      (([[UIScreen mainScreen] bounds].size.height == 568) ? YES : NO)
#define IS_IPhone6      (667 == [[UIScreen mainScreen] bounds].size.height ? YES : NO)
#define IS_IPhone6plus  (736 == [[UIScreen mainScreen] bounds].size.height ? YES : NO)

/** 保存数据到偏好设置 */
#define SaveUserDefault(key,Obj) \
({  if (!isNull(key) && !isNull(Obj) && key != nil  && Obj != nil) { \
[[NSUserDefaults standardUserDefaults] setObject:Obj forKey:key]; \
[[NSUserDefaults standardUserDefaults] synchronize]; } \
})

/** 获取偏好设置数据 */
#define GetUserDefault(key)  key!=nil ? [[NSUserDefaults standardUserDefaults] objectForKey:key] : nil


#define isBoss ([GJGlobalManager shareInstance].currentShopInfo.operatorType==1)

#define GJ_CashierId (isBoss?@"":@([GJGlobalManager shareInstance].currentShopInfo.operatorId))

#define CurrentUserName ([GJGlobalManager shareInstance].lastLoginAccount)


/**
 * 拷贝自定义对象,NSCopy协议的具体实现
 */
#define GJCopyImplementation \
- (id)copyWithZone:(NSZone *)zone \
{ \
Class clazz = [self class]; \
id model = [[clazz allocWithZone:zone] init]; \
[clazz mj_enumerateProperties:^(MJProperty *property, BOOL *stop) {\
id obj = [self valueForKey:property.name];\
[model setValue:obj forKey:property.name];\
}];\
return model;\
}

//一个宏实现自定义对象的NSCopy协议
#define GJExtensionCopyImplementation  GJCopyImplementation

/*
 对象类型判断
 */
#define isNil(obj) (obj)
#define isNull(obj) ((NSNull *)obj==[NSNull null])
#define isString(obj) ([obj isKindOfClass:[NSString class]])
#define isValidString(obj) (isString(obj)&&((NSString *)obj).length)
#define isNumber(obj) ([obj isKindOfClass:[NSNumber class]])
#define isArray(obj) ([obj isKindOfClass:[NSArray class]])
#define isValidArray(obj) (isArray(obj)&&((NSArray *)obj).count)
#define isDictionary(obj) ([obj isKindOfClass:[NSDictionary class]])
#define isValidDictionary(obj) ([obj isKindOfClass:[NSDictionary class]]&&((NSDictionary *)obj).allKeys.count)
#define returnNilIfNotString(obj) (isString(obj)?obj:nil)

/*
    MBProgressHUD
 */
#define MB_ShowLoadingToast [MBProgressHUD showLoadingOnWindowWithText:nil];
#define MB_HideLoadingToat [MBProgressHUD hideLoadingFromWindow];
#define MB_ShowText(text) [MBProgressHUD showError:text model:NO];

#endif



